{extend name="index/base" /}
{block name="style"}
<style type="text/css">
.pic img{width: 100px;height: 100px;}
</style>
{/block}
{block name="body"}
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">商品ID</label>
    <div class="layui-input-inline">
       <input type="number" name="item_id" value="{$info.item_id}" required  lay-verify="required" placeholder="例：562107652068" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux" style="padding: 4px 0 !important;"><a href="javascript:;" id="collect" class="layui-btn layui-btn-sm">采集信息</a></div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" value="{$info.title}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品图片</label>
    <div class="layui-input-block">
      <input type="text" name="pic" value="{$info.pic}" required  lay-verify="required" placeholder="请输入图片链接" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux" style="margin-left: 110px;">
      <div class="pic">
        <img src="{$info.pic|default="__IMG__/noimage.gif"}">&nbsp;&nbsp;
        <button type="button" class="layui-btn layui-btn-sm" id="upimg"><i class="layui-icon">&#xe67c;</i>上传自定义图片</button>
      </div>
      
      
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">销售价</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="price" value="{$info.price}" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">优惠券金额</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="quan_price" value="{$info.quan_price}" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">券后价</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="price_after_quan" value="{$info.price_after_quan}" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">佣金比例</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="rate" value="{$info.rate}" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">%</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">销量</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="sales" value="{$info.sales}"  placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">是否天猫</label>
    <div class="layui-input-inline">
      <select name="is_tmall" lay-verify="required">
        <option value="1">天猫</option>
        <option value="0">淘宝</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" style="color: red;">设定返还金额</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="return_money" value="{$info.return_money}" required  lay-verify="required"   placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" style="color: red;">需要免单券</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="need_quan" value="{$info.need_quan}" required  lay-verify="required"   placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" style="color: red;">排序</label>
    <div class="layui-input-inline" style="width: 100px;">
      <input type="number" name="sort" value="{$info.sort}" required  lay-verify="required"   placeholder="" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">*数字越大越靠前</div>
  </div>
  <div class="layui-form-item layui-sumbtn">
    <input type="hidden" name="id" value="{$info.id}">
	  <div class="layui-input-block">
	    <button class="layui-btn self_window" lay-submit="" lay-filter="ajax-post" type="submit" target-form="layui-form">立即提交</button>
	    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	  </div>
  </div>
</form>
{/block}

{block name="script"}
<script type="text/javascript">
layui.config({
     base: '/static/js/',
});
layui.use(['tool','upload'],function(){
	var $ = layui.jquery,form=layui.form,tool=layui.tool,upload = layui.upload;
  //采集信息
  $('#collect').click(function(){
    var item_id = $('input[name=item_id]').val();
    if (item_id=='') {
      layer.msg('请输入商品ID');
      return false;
    }
    $.post('{:url('item_info')}',{item_id:item_id},function(ret){
      if (ret.code==1) {
        var data = ret.msg;
        $('input[name=title]').val(data.item.title);
        $('input[name=pic]').val('https:'+data.item.picUrl);
        $('.pic img').attr('src','https:'+data.item.picUrl+'_100x100.jpg');
        $('input[name=price]').val(data.item.discountPrice);
        var quan_price = data.amount||0;
        $('input[name=quan_price]').val(quan_price);
        $('input[name=price_after_quan]').val(data.item.discountPrice-quan_price);
        $('input[name=rate]').val(data.max_commission_rate);
        $('input[name=sales]').val(data.item.biz30Day);
        tool.setValue('is_tmall',data.item.tmall||'0')
      }else{
        layer.msg(ret.msg);
      }
    })
  })
  //上传图
  var uploadInst4 = upload.render({
    elem: '#upimg' //绑定元素
    ,url: '{:url('Ajax/upload')}' //上传接口
    ,exts:'png|jpg'//只允许上传png
    ,done: function(res){
      //上传完毕回调
      if (res.code==1) {
          $('input[name=pic]').val('{:config('site.domain')}'+res.data.url);
          $('.pic img').attr('src',res.data.url);
        }else{
          layer.msg(res.data,{icon:2});
        }
    }
    ,error: function(){
      //请求异常回调
      layer.msg('上传异常~');
    }
  });


});
</script>
{/block}